using System;
using Microsoft.SPOT;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using SDCard;

using WebServer;

    public class IndexPage
    {
        public string GetIndexPage(BaseRequest request, float[] temperaturesInCelsius, SDCard.SDCard sdCard)// todo put in stylesheet
        {
            ConsoleWrite.Print("Command received:" + request.Uri);
            string dateTimeString = DateTime.Now.ToString("u");
            string temperatureLines = "";
            for (int i = 3; i < temperaturesInCelsius.Length; i++)
            {
                //string temperatureString = StringUtility.Format("{0:F2}", temperaturesInCelsius[i]);
                string temperatureString = temperaturesInCelsius[i].ToString("F");
                temperatureLines += "<p>The temperature at sensor " + i.ToString() + " is : " + temperatureString + "C</p>";
            }

            // todo StringBuilder
            
            string line3 = "<p>The time is: " + dateTimeString + "</p>";
            string line4 = "<p>The uri is: " + request.Uri + "</p>";
            string line5 = "<p>Log File is: " + A2D.LogFileName + "</p>";
            

            string line6 = "<p>Memory available is: " + ConsoleWrite.MemoryCollect(true).ToString() + " bytes</p>";//                            
            string line7 = "<p><a href=\"/Netduino/rumnblowey.htm?dataUri=/" + A2D.LogFileName + "\">View Graph</a></p>";//          
            TimeSpan uptime = DateTime.Now - NetduinoTime.BootTime;
            string line8 = "<p>Uptime is: " + uptime.ToString() + "</p>";
            string line9 = "<p>Total Page requests = " + WebServer.WebServer.PageRequestCount.ToString() + "</p>";
            string content = HtmlGeneral.HtmlStart + temperatureLines + line3 + line4 + line5 + line6 + line7 + line8 + line9 + HtmlGeneral.HtmlEnd;
            string header = HttpGeneral.GetHttpHeader(content.Length, "text/html", 10);
            return header + content;
        }
    }
